package com.cyt.web.controller.phone;

import com.cyt.base.enums.BusinessType;
import com.cyt.base.enums.OperatorType;
import com.cyt.base.model.dto.ReturnResult;
import com.cyt.sys.aspect.BaseLog;
import com.cyt.web.controller.base.PhoneController;
import com.cyt.work.site.model.po.NoticeRecord;
import com.cyt.work.site.model.vo.*;
import com.cyt.work.site.service.*;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author rong yuan
 * @date 2019/7/9 09:53
 */
@RestController
public class PhoneSiteController extends PhoneController {

    @Resource
    private NoticeService noticeService;
    @Resource
    private BannerService bannerService;
    @Resource
    private StudentService studentService;
    @Resource
    private NoticeRecordService noticeRecordService;
    @Resource
    private TeacherService teacherService;
    @Resource
    private SchoolService schoolService;

    /**
     * 跳转校园资讯分类界面
     *
     * @param token    用户信息
     * @param applyId  应用ID
     * @param noticeVo 接受参数对象
     * @return ModelAndView
     * @author rong yuan
     * @date 2019/7/9 09:08
     */
    @BaseLog(module = "微官网", classz = "校园资讯", methods = "跳转校园资讯分类界面", businessType = BusinessType.GET, operatorType = OperatorType.MOBILE)
    @RequestMapping(value = "/phone/notice/noticeCategory")
    public ModelAndView noticeCategory(String token, String applyId, NoticeVo noticeVo) {
        ModelAndView modelAndView = new ModelAndView("/mobile/notice/noticeCategory");
        modelAndView.addObject("token", token);
        modelAndView.addObject("applyId", applyId);
        noticeVo.setMemberId(acceptToken(token).getId());
        modelAndView.addObject("num", noticeService.noticeCategory(noticeVo));
        return modelAndView;
    }

    /**
     * 跳转校园资讯列表界面
     *
     * @param token    用户信息
     * @param applyId  应用ID
     * @param noticeVo 接受参数对象
     * @return ModelAndView
     * @author rong yuan
     * @date 2019/7/9 09:08
     */
    @BaseLog(module = "微官网", classz = "校园资讯", methods = "跳转校园资讯列表界面", businessType = BusinessType.GET, operatorType = OperatorType.MOBILE)
    @RequestMapping(value = "/phone/notice/noticeList")
    public ModelAndView noticeList(String token, String applyId, NoticeVo noticeVo) {
        ModelAndView modelAndView = new ModelAndView("/mobile/notice/noticeList");
        modelAndView.addObject("token", token);
        modelAndView.addObject("applyId", applyId);
        modelAndView.addObject("noticeType", noticeVo.getNoticeType());
        return modelAndView;
    }

    /**
     * 分页查询
     *
     * @param noticeVo 接受参数对象
     * @param page     当前页面
     * @param limit    页面数量
     * @return ReturnResult
     * @author rong yuan
     * @date 2019-7-8 15:17:40
     */
    @BaseLog(module = "微官网", classz = "校园资讯", methods = "分页查询对象", businessType = BusinessType.GET, operatorType = OperatorType.MANAGE)
    @RequestMapping(value = "/phone/notice/page", method = RequestMethod.POST)
    public ReturnResult page(NoticeVo noticeVo, int page, int limit) {
        return noticeService.page(noticeVo, page, limit);
    }

    /**
     * 跳转校园资讯详情界面
     *
     * @param token    用户信息
     * @param applyId  应用ID
     * @param noticeVo 接受参数对象
     * @return ModelAndView
     * @author rong yuan
     * @date 2019/7/9 09:08
     */
    @BaseLog(module = "微官网", classz = "校园资讯", methods = "跳转校园资讯详情界面", businessType = BusinessType.GET, operatorType = OperatorType.MOBILE)
    @RequestMapping(value = "/phone/notice/noticeDetail")
    public ModelAndView noticeDetail(String token, String applyId, NoticeVo noticeVo) {
        ModelAndView modelAndView = new ModelAndView("/mobile/notice/noticeDetail");
        modelAndView.addObject("token", token);
        modelAndView.addObject("applyId", applyId);
        //记录阅读状态
        NoticeRecordVo noticeRecordVo = new NoticeRecordVo();
        noticeRecordVo.setNoticeId(noticeVo.getId());
        noticeRecordVo.setMemberId(acceptToken(token).getId());
        NoticeRecord noticeRecord = noticeRecordService.findOne(noticeRecordVo);
        if (noticeRecord == null) {
            noticeRecordService.addOrUpdate(noticeRecordVo, null);
        }
        List<NoticeVo> noticeVoList = noticeService.list(noticeVo);
        if (noticeVoList != null) {
            modelAndView.addObject("noticeVo", noticeVoList.get(0));
        }
        return modelAndView;
    }

    /**
     * 跳转报名界面
     *
     * @param token   用户信息
     * @param applyId 应用ID
     * @return ModelAndView
     * @author rong yuan
     * @date 2019/7/9 09:08
     */
    @BaseLog(module = "微官网", classz = "新生报名", methods = "跳转报名界面", businessType = BusinessType.GET, operatorType = OperatorType.MOBILE)
    @RequestMapping(value = "/phone/student/studentSignUp")
    public ModelAndView studentSignUp(String token, String applyId) {
        ModelAndView modelAndView = new ModelAndView("/mobile/student/studentSignUp");
        modelAndView.addObject("token", token);
        modelAndView.addObject("applyId", applyId);
        return modelAndView;
    }

    /**
     * 保存或更新
     *
     * @param applyId   应用ID
     * @param studentVo 接受参数对象
     * @return ReturnResult
     * @author rong yuan
     * @date 2019-7-8 19:39:31
     */
    @BaseLog(module = "微官网", classz = "新生报名", methods = "保存或更新对象", businessType = BusinessType.INSERT, operatorType = OperatorType.MANAGE)
    @RequestMapping(value = "/phone/student/addOrUpdate", method = RequestMethod.POST)
    public ReturnResult addOrUpdate(String applyId, StudentVo studentVo) {
        studentVo.setApplyId(applyId);
        return studentService.addOrUpdate(studentVo, null);
    }

    /**
     * 跳转学校简介界面
     *
     * @param token    用户信息
     * @param applyId  应用ID
     * @param schoolVo 接受参数对象
     * @return ModelAndView
     * @author rong yuan
     * @date 2019/7/9 09:08
     */
    @BaseLog(module = "微官网", classz = "学校简介", methods = "跳转学校简介界面", businessType = BusinessType.GET, operatorType = OperatorType.MOBILE)
    @RequestMapping(value = "/phone/school/schoolInfo")
    public ModelAndView schoolInfo(String token, String applyId, SchoolVo schoolVo) {
        ModelAndView modelAndView = new ModelAndView("/mobile/school/schoolInfo");
        modelAndView.addObject("token", token);
        modelAndView.addObject("applyId", applyId);
        modelAndView.addObject(schoolService.selectSchool(schoolVo));
        BannerVo bannerVo = new BannerVo();
        bannerVo.setApplyId(applyId);
        bannerVo.setBannerType(String.valueOf(2));
        bannerVo.setStatus(String.valueOf(1));
        modelAndView.addObject(bannerService.list(bannerVo));
        return modelAndView;
    }

    /**
     * 跳转教师风采界面
     *
     * @param token   用户信息
     * @param applyId 应用ID
     * @return ModelAndView
     * @author rong yuan
     * @date 2019/7/9 09:08
     */
    @BaseLog(module = "微官网", classz = "教师风采", methods = "跳转教师风采界面", businessType = BusinessType.GET, operatorType = OperatorType.MOBILE)
    @RequestMapping(value = "/phone/teacher/teacherList")
    public ModelAndView teacherList(String token, String applyId) {
        ModelAndView modelAndView = new ModelAndView("/mobile/teacher/teacherList");
        modelAndView.addObject("token", token);
        modelAndView.addObject("applyId", applyId);
        return modelAndView;
    }

    /**
     * 分页查询
     *
     * @param teacherVo 接受参数对象
     * @param page      当前页面
     * @param limit     页面数量
     * @return ReturnResult
     * @author rong yuan
     * @date 2019-7-8 15:17:40
     */
    @BaseLog(module = "微官网", classz = "教师风采", methods = "分页查询对象", businessType = BusinessType.GET, operatorType = OperatorType.MANAGE)
    @RequestMapping(value = "/phone/teacher/page", method = RequestMethod.POST)
    public ReturnResult page(TeacherVo teacherVo, int page, int limit) {
        return teacherService.pageVo(teacherVo, page, limit);
    }

    /**
     * 跳转教师风采详情界面
     *
     * @param token     用户信息
     * @param applyId   应用ID
     * @param teacherVo 接受参数对象
     * @return ModelAndView
     * @author rong yuan
     * @date 2019/7/9 09:08
     */
    @BaseLog(module = "微官网", classz = "教师风采", methods = "跳转教师风采详情界面", businessType = BusinessType.GET, operatorType = OperatorType.MOBILE)
    @RequestMapping(value = "/phone/teacher/teacherDetail")
    public ModelAndView teacherDetail(String token, String applyId, TeacherVo teacherVo) {
        ModelAndView modelAndView = new ModelAndView("/mobile/teacher/teacherDetail");
        modelAndView.addObject("token", token);
        modelAndView.addObject("applyId", applyId);
        List<TeacherVo> teacherVoList = teacherService.list(teacherVo);
        if (teacherVoList != null) {
            modelAndView.addObject("teacherVo", teacherVoList.get(0));
        }
        return modelAndView;
    }

    /**
     * 跳转联系我们界面
     *
     * @param token    用户信息
     * @param applyId  应用ID
     * @param schoolVo 接受参数对象
     * @return ModelAndView
     * @author rong yuan
     * @date 2019/7/9 09:08
     */
    @BaseLog(module = "微官网", classz = "联系我们", methods = "跳转联系我们界面", businessType = BusinessType.GET, operatorType = OperatorType.MOBILE)
    @RequestMapping(value = "/phone/school/contactInfo")
    public ModelAndView contactInfo(String token, String applyId, SchoolVo schoolVo) {
        ModelAndView modelAndView = new ModelAndView("/mobile/school/contactInfo");
        modelAndView.addObject("token", token);
        modelAndView.addObject("applyId", applyId);
        modelAndView.addObject(schoolService.selectSchool(schoolVo));
        return modelAndView;
    }

    /**
     * 跳转校园风采界面
     *
     * @param token    用户信息
     * @param applyId  应用ID
     * @param schoolVo 接受参数对象
     * @return ModelAndView
     * @author rong yuan
     * @date 2019/7/9 09:08
     */
    @BaseLog(module = "微官网", classz = "校园风采", methods = "跳转校园风采界面", businessType = BusinessType.GET, operatorType = OperatorType.MOBILE)
    @RequestMapping(value = "/phone/school/schoolStyle")
    public ModelAndView schoolStyle(String token, String applyId, SchoolVo schoolVo) {
        ModelAndView modelAndView = new ModelAndView("/mobile/school/schoolStyle");
        modelAndView.addObject("token", token);
        modelAndView.addObject("applyId", applyId);
        modelAndView.addObject(schoolService.selectSchool(schoolVo));
        return modelAndView;
    }

    /**
     * 跳转定位界面
     *
     * @param token    用户信息
     * @param applyId  应用ID
     * @param schoolVo 接受参数对象
     * @return ModelAndView
     * @author rong yuan
     * @date 2019/7/9 09:08
     */
    @BaseLog(module = "微官网", classz = "联系我们", methods = "跳转定位界面", businessType = BusinessType.GET, operatorType = OperatorType.MOBILE)
    @RequestMapping(value = "/phone/school/contactMap")
    public ModelAndView contactMap(String token, String applyId, SchoolVo schoolVo) {
        ModelAndView modelAndView = new ModelAndView("/mobile/school/contactMap");
        modelAndView.addObject("token", token);
        modelAndView.addObject("applyId", applyId);
        modelAndView.addObject(schoolService.selectSchool(schoolVo));
        return modelAndView;
    }
}